var http = require("http")
var querystring =  require("querystring")

var postData = querystring.stringify({
	"content":"一起期待,我的测试……",
	"mid":8194
})

var options = {
	hostname : "www.imooc.com",
	port:80,
	path:"/course/docomment",
	method:"POST",
	headers:{
		'Accept':'application/json, text/javascript, */*; q=0.01',
		'Accept-Encoding':'gzip, deflate',
		'Accept-Language':'zh-CN,zh;q=0.8,en;q=0.6',
		'Cache-Control':'no-cache',
		'Connection':'keep-alive',
		'Content-Length':postData.length,
		'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
		'Cookie':'imooc_uuid=5adb5698-0db8-49e1-9a6e-575cb6a30131; imooc_isnew_ct=1499322604; UM_distinctid=15dc0eeeef7787-07df3cb5c17624-50462f1d-15f900-15dc0eeeef82a8; CNZZDATA1261110065=864919494-1502176157-https%253A%252F%252Fwww.baidu.com%252F%7C1502176157; PHPSESSID=d97v596hs5bmpiodsnmgo7oec2; loginstate=1; apsid=ZhNjA2NGUwMGM2YzExM2UyOTI4YzkzMjQ3ZWM0NGYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANTk3NDg4OQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABqd2x4enlzamRAMTYzLmNvbQAAAAAAAAAAAAAAAAAAADdiZWYzZmY1NjA3OWY4NzIxYTVhMzUxMDYwMzNjYmQ3yZjcWcmY3Fk%3DMD; last_login_username=jwlxzysjd%40163.com; IMCDNS=0; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1506327061,1507545090,1507609322,1507610051; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1507631175; imooc_isnew=2; cvde=59dc4ae814a6f-346',
		'Host':'www.imooc.com',
		'Origin':'http://www.imooc.com',
		'Pragma':'no-cache',
		'Referer':'http://www.imooc.com/video/8194',
		'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
		'X-Requested-With':'XMLHttpRequest'
	},

}

var req = http.request(options,function(res){
	console.log("status" + res.statusCode) //状态码
	console.log("headers" + JSON.stringify(res.headers))
	// 我们接受post数据时，node是以流的形式发送上来的，会触发ondata事件，所以我们见到很多代码是这样写的：
	res.on("data",function(chunk){
		console.log(Buffer.isBuffer(chunk))
		console.log(typeof chunk)
	})

	res.on("end",function(){
		console.log("评论完毕")
	})

})
req.on("error",function(){
	console.log("error" + e.message)
})
req.write(postData)

req.end()

